"""
主题: 创建UDP服务器
问题: 你想实现一个基于UDP协议的服务器来与客户端通信。
提示 : 
"""

from socketserver import BaseRequestHandler, UDPServer
import time

class TimeHandler(BaseRequestHandler):
    def handle(self):
        print('Got connection from', self.client_address)
        # Get message and client socket
        msg, sock = self.request
        print("Recive :", msg)
        resp = time.ctime()
        sock.sendto(resp.encode('ascii'), self.client_address)

if __name__ == '__main__':
    serv = UDPServer(('', 20001), TimeHandler)
    serv.serve_forever()